package com.py.credit.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.py.credit.dao.PromiseBookStatisticsDao;
import com.py.credit.dao.XylyStatisticsServiceDao;
import com.py.credit.service.XylyStatisticsService;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;
import com.py.framework.core.exception.ServiceException;
@Service
public class XylyStatisticsServiceImpl implements XylyStatisticsService {

	@Autowired
	XylyStatisticsServiceDao xylyStatisticsServiceDao;

	@Override
	public List<Map<String,Object>> getPromiseBooksByConditionForPage(
			String type,String ztType,Long deptId,
			List<String> columns, String[] additionalColumns, String condition, Page page){
		
		if (CollectionUtils.isEmpty(columns)) {
            throw new ServiceException("至少选择一列");
        }
        List<String> conditions = SQLBuilder.createConditionSql(condition);
        
        List<Map<String, Object>> list = xylyStatisticsServiceDao.getPromiseBooksByConditionForPage(type,ztType,deptId,
        		columns,additionalColumns, conditions, page);
		
		return list;
	}

	@Override
	public List<Map<String, Object>> getStatistics(String type , String ztType , Long topDeptId) {
		return xylyStatisticsServiceDao.getStatistics(type,ztType,topDeptId);
	}
	
	@Override
	public List<Map<String, Object>> getStatisticsForPage(Page page) {
		return xylyStatisticsServiceDao.getStatisticsForPage(page);
	}

	@Override
	public List<Map<String, Object>> promiseBooksByZtForPage(String ztName , List<String> columns, String[] additionalColumns, String condition, Page page) {
		if (CollectionUtils.isEmpty(columns)) {
            throw new ServiceException("至少选择一列");
        }
        List<String> conditions = SQLBuilder.createConditionSql(condition);
		return xylyStatisticsServiceDao.promiseBooksByConditionForPage(ztName ,columns ,additionalColumns,conditions,page);
	}

	@Override
	public List<Map<String, Object>> getAllTopDepts() {
		return xylyStatisticsServiceDao.getAllTopDepts();
	}

	@Override
	public Map<String, Object> getStatisticsByType(String type,String tablename) {
		return xylyStatisticsServiceDao.getStatisticsByType(type,tablename);
	}

}
